package com.rdc.qingkou.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.githang.statusbar.StatusBarCompat;
import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.R;
import com.rdc.qingkou.view.fragment.OneLevelCommentFragment;


public class CommentActivity extends AppCompatActivity {


    public TextView title;
    public boolean isOneLevelComment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.addActivity(this);
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.White), true);
        setContentView(R.layout.activity_comment);
        initViews();
        int mCardId = getIntent().getIntExtra("cardId", 0);
        OneLevelCommentFragment oneLevelCommentFragment = new OneLevelCommentFragment();
        oneLevelCommentFragment.setCardId(mCardId);
        replaceFragment(oneLevelCommentFragment);
    }

    public final void replaceFragment(Fragment fragment) {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.comment_fragment, fragment);
        transaction.addToBackStack(null);
        transaction.commit();
    }

    private void initViews() {
        title = (TextView) findViewById(R.id.title_content_textView);
        ImageButton back = (ImageButton) findViewById(R.id.title_back_imageButton);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
    }

    @Override
    public void onBackPressed() {
        if (isOneLevelComment) {
            finish();
        }
        super.onBackPressed();

    }
}


